﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.Text.RegularExpressions;
using System.Net;

namespace Obra.Test
{
    [TestFixture]
    public class HttpServerMatchedContentTester
    {
        private readonly Uri uri = new Uri(Messages.TestUrl);

        [Test]
        public void HttpServerTest()
        {
            Obra.Common.GzipWebRequest.Register();

            using (HttpServerMatchedContent httpServer = new HttpServerMatchedContent(this.uri))
            {
                httpServer.MatchedContents.Add(
                    new MatchedContentString("naples", "naples"));
                httpServer.MatchedContents.Add(
                    new MatchedContentString("venice", "venice"));

                httpServer.DefaultMatchContent = new MatchedContentString("rome");
                httpServer.Start();

                string naples = String.Format("{0}/naples", Messages.TestUrl);
                string venice = String.Format("{0}/venice", Messages.TestUrl);

                Assert.AreEqual("naples", TestHelper.Fetch(new Uri(naples)));
                Assert.AreEqual("venice", TestHelper.Fetch(new Uri(venice)));

                WebRequest request = HttpWebRequest.Create(naples);
                var response = request.GetResponse();

                Assert.AreEqual("rome", TestHelper.Fetch(this.uri));
            }
        }
    }
}
